<template>
  <view class="add-wifi">
    <wTitleBar :bgColor="'#1296db'" title="添加WIFI"></wTitleBar>
    <div class="container-user-body">
      <div class="container-user-body-items">
        <div class="input-name">WIFI名称(SSID)：</div>
        <input class="input-edit" type="text" placeholder="请填写您的wifi名称" :maxlength="20" v-model="form.wifiSsid" />
      </div>
      <div class="container-user-body-items">
        <div class="input-name">WIFI密码：</div>
        <input class="input-edit" type="text" placeholder="请填写您的wifi密码" :maxlength="20" v-model="form.wifiPassword" />
      </div>
      <div class="flex-jl">
        <div class="submit-btn" @tap="submit">提交</div>
      </div>
    </div>
  </view>
</template>

<script>
import wTitleBar from "@/components/w-titleBar/w-titleBar.vue";
import wifi from "@/api/common";
import Dialog from "@/wxcomponents/vant/dialog/dialog";
export default {
  components: {
    wTitleBar
  },
  data() {
    return {
      show: false,
      form: {
        wifiSsid: "",
        wifiPassword: ""
      },
      typeName: ""
    };
  },
  async onShow() {
    this.setTabBarIndex(2); // 自定义tabbar下标
  },

  methods: {
    submit() {
      if (!this.form.wifiSsid) {
        uni.showToast({
          title: "请填写您的wifi名称",
          icon: "none"
        });
        return false;
      }
      if (!this.form.wifiPassword) {
        uni.showToast({
          title: "请填写您的wifi密码",
          icon: "none"
        });
        return false;
      }
      wifi.addData(this.form).then((res) => {
        if (res.status == 1) {
          Dialog.alert({
            message: "提交成功"
          }).then(() => {
            /*    // on close
          Object.keys(this.form).map((key) => this.form[key] == "");
          this.form.contentType = 1;
          uni.switchTab({
            url: "/pages/index/user"
          }); */
          });
        } else {
          uni.showToast({
            title: res.msg,
            icon: "none"
          });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.add-wifi {
  width: 100%;
  background-color: #f3f3f3;

  .container-user-body {
    margin: 80px 10px 0;
    background-color: #fff;
    border-radius: 8px;
    flex-direction: column;
    display: flex;
  }

  .container-user-body-items {
    height: 44px;
    display: flex;
    align-items: center;
    margin: 0 10px;
    justify-content: space-between;
    border-bottom: 1px solid #f3f3f3;
  }

  .input-name {
    color: #000000;
    size: 12px;
  }

  .input-edit {
    text-align: left;
  }

  .submit-btn {
    width: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1296db;
    border-radius: 20px;
    color: #fff;
    font-size: 16px;
    height: 34px;
    font-weight: bold;
    margin: 80px 0 40px;
  }
}
</style>
